package com.itheima.admin.controller;

import com.baomidou.mybatisplus.extension.service.IService;
import com.itheima.admin.dto.ChannelPageRequestDto;
import com.itheima.admin.pojo.AdChannel;
import com.itheima.admin.service.AdChannelService;
import com.itheima.common.enums.HttpCodeEnum;
import com.itheima.common.vo.PageResultVo;
import com.itheima.common.vo.ResultVo;
import com.itheima.core.controller.AbstractCoreController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 频道管理
 */
@RestController
@RequestMapping("/channel")
@Api(tags = "频道管理")
public class AdChannelController extends AbstractCoreController<AdChannel> {


    private AdChannelService adChannelService;

    @Autowired
    public AdChannelController(AdChannelService adChannelService) {
        super(adChannelService);
        this.adChannelService = adChannelService;
    }

    /**
     * 频道分页查询
     */
    @ApiModelProperty("频道分页查询")
    @PostMapping("/list")
    public PageResultVo pageList(@RequestBody ChannelPageRequestDto dto){
        PageResultVo vo = adChannelService.pageList(dto);
        return vo;
    }


    /**
     * 新增频道
     * @param adChannel
     * @return
     */
    /*@ApiModelProperty("新增频道")
    @PostMapping("/add")
    public ResultVo add(@RequestBody AdChannel adChannel){
        //NPW 空指针
        if (null == adChannel){
            return ResultVo.error(HttpCodeEnum.PARAM_REQUIRE);
        }
        adChannel.setIsDefault(false);
        adChannel.setCreatedTime(new Date());
        if (adChannelService.save(adChannel)) {
            return ResultVo.ok();
        }
        return ResultVo.error();
    }*/


    /**
     * 通过id查询
     * @param id
     * @return
     */
    /*@ApiOperation("通过id查询")
    @GetMapping("/{id}")
    public ResultVo findById(@PathVariable Integer id){
        return ResultVo.ok(adChannelService.getById(id));
    }
*/

    /**
     * 更新频道
     * @param adChannel
     * @return
     */
    /*@ApiModelProperty("更新频道")
    @PostMapping("/update")
    public ResultVo update(@RequestBody AdChannel adChannel){
        //NPW 空指针
        if (null == adChannel || null == adChannel.getId()){
            return ResultVo.error(HttpCodeEnum.PARAM_REQUIRE);
        }
        if (adChannelService.updateById(adChannel)) {
            return ResultVo.ok();
        }
        return ResultVo.error();
    }*/

    /**
     * 删除频道
     * @param id
     * @return
     */
    /*@ApiModelProperty("删除频道")
    @DeleteMapping("/del/{id}")
    public ResultVo deleteById(@PathVariable(value = "id") Integer id){
        if (adChannelService.removeById(id)) {
            return ResultVo.ok();
        }
        return ResultVo.error();
    }*/

}
